
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<link href="${ctx}/css/pass.css" rel="stylesheet">
<script type="text/javascript">
	/*树形表格设置*/
	var setting = {
			check: {
				enable: true,
				chkStyle: "radio",
				radioType: "all"
			},
			view: {
				dblClickExpand: false
			},
			  data: {
		    	 simpleData: {//简单数据模式
			     	 enable:true,
			      	 idKey: "id",
			     	 pIdKey: "parentId",
			    	 rootPId: null
		  	  }
		 	 },
			callback: {
				onClick: onClick,
				onCheck: onCheck
			}
	};
	
	
	
	function onClick(e, treeId, treeNode) {
		e.preventDefault();
		var zTree = $.fn.zTree.getZTreeObj("permissionZtree");
		zTree.checkNode(treeNode, !treeNode.checked, null, true);
		return false;
	}	
	
	function onCheck(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("permissionZtree"),
			nodes = zTree.getCheckedNodes(true),
			v = "";
			pId = "";
			for (var i=0, l=nodes.length; i<l; i++) {
				v += nodes[i].name + ",";
				pId += nodes[i].id + ",";
			}
			if (v.length > 0 ) v = v.substring(0, v.length-1);
			if (pId.length > 0 ) pId = pId.substring(0, pId.length-1);
			var parentName = $("#parent_name");
			var parentId = $("#parentId");
			parentName.attr("value", v);
			parentId.attr("value",pId)
			hideMenu();
	}
	
	function showPermissonList(){
		console.log("点击方法调用开始");
		var parentName = $("#parent_name");
		var offset = $("#parent_name").offset();
		$("#content").slideDown("fast");
		console.log("点击方法调用结束");
		 $("body").bind("mousedown", onBodyDown);
	}
	
	function hideMenu() {
			$("#content").fadeOut("fast");
			$("body").unbind("mousedown", onBodyDown);
	}
	
 	function onBodyDown(event) {
			if (!(event.target.id == "menuBtn" || event.target.id == "parent_name" || event.target.id == "content" || $(event.target).parents("#content").length>0)) {
				hideMenu();
			}
	}

	function onLoadZTree(){
	     var t = $("#permissionZtree");
	  	 t = $.fn.zTree.init(t, setting, ${treeNodes});   
	} 
	
	function setAttr(){
	 if("add"==$('#op').val()){
			$('#is_used').attr("disabled","disabled");
		}else{
			$('#is_used').removeAttr();
		}	
	}
	$(document).ready(function(){
		onLoadZTree();
		setAttr();
	});
</script>
<div class="bjui-pageContent">
    <form action="${ctx}/sys/sysPermissionAction/doSave" class="pageForm" data-toggle="validate">
    	<input type="hidden" name="ctxPath" id="ctx_path" value="${ctx}">
        <input type="hidden" id="op" name="op" value="${param.op}${op}">
	        <input type="hidden" name="id" id="id" value="${permission.id}">
	        <input type="hidden" name="parentId" id="parentId" value="${permission.parentId}">
	        <input type="hidden" name="state" id="state" value="${permission.state}">
	        <input type="hidden" name="createUser" id="createUser" value="${permission.createUser}">
	        <input type="hidden" name="modifyUser" id="modifyUser" value="${permission.modifyUser}">
	        <input type="hidden" name="iconCls" id="iconCls" value="${permission.iconCls}">
	        <input type="hidden" name="status" id="status" value="${permission.status}">
        <table class="table table-condensed table-hover">
            <tbody>
                <tr>
                    <td colspan="2" align="center" valign="middle"><h4>${title}</h4></td>
                </tr>
                <tr>
                    <td>
                        <label for="name" class="control-label x90">权限名称：</label>
                          <input class="" id="name" type="text" name="name" value="${permission.name}" data-rule="required;name;remote[${ctx}/sys/sysPermissionAction/doNameValidate?op=${op}&original=${permission.name}]" />
                    </td>
        			 <td>
                        <label for="parent_name" class="control-label x90">父权限名称：</label>
                          <input class="m_readonly" id="parent_name" type="text" name="parentName" readonly value="${permission.parentName}" onclick="showPermissonList()"/>
                    	    <div id="content" class="m_ztree_content" style="display:none; position: absolute;">
							<ul id="permissionZtree" class="ztree" style="margin-top:0; width:160px;"></ul>
							</div>
                    </td>                   
                </tr>
                <tr>
                    <td>
                        <label for="url" class="control-label x90">权限路径：</label>
                          <input class="" id="url" type="text" name="url"  value="${permission.url}" data-rule="required;" />
                    </td>
        			 <td>
                        <label for="sys_id" class="control-label x90">权限编码：</label>
                          <input class="" id="sys_id" type="text" name="sysId"  value="${permission.sysId}" data-rule="required;sysId;remote[${ctx}/sys/sysPermissionAction/doSysIdValidate?op=${op}&original=${permission.sysId}]" />
                    </td>                   
                </tr>
                 <tr>
                 	 <td>
                        <label for="seq_idx" class="control-label x90">权限排序：</label>
                          <input class="" id="seq_idx" type="number" name="seqIdx"  value="${permission.seqIdx}" data-rule="required;" />
                    </td>  
                    <td>
                        <label for="open" class="control-label x90">折叠标志：</label>
                        <select id="open" name="open" data-toggle="selectpicker">
					   		<option value="1">展开</option>
					   		<option value="0">折叠</option>
					   	</select>
                    </td>                  
                </tr>     
                <tr>
                    <td>
                        <label for="type" class="control-label x90">权限类型：</label>
                        <select id="type" name="type" data-toggle="selectpicker">
					   		<option value="F">菜单</option>
					   		<option value="O">操作</option>
					   	</select>
                     <%--   <input  id="type" type="hidden" name="type" value="${permission.type}" data-rule="required;" /> --%>
                    </td>
        			 <td>
                        <label for="is_used" class="control-label x90">启用：</label>
                        <select id="is_used" name="isUsed" data-toggle="selectpicker">
					   		<option value="Y" selected="selected">启用</option>
					   		<option value="N">禁用</option>
					   	</select>
                    </td>                   
                </tr>             
                 <tr>
                    <td colspan="2">
                        <label for="description" class="control-label x90">权限描述：</label>
                        <textarea name="description" id="description" rows="5" cols="58">${permission.description}</textarea>
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
</div>
<div class="bjui-pageFooter">
    <ul>
        <li><button type="button" class="btn-close" data-icon="close">关闭</button></li>
        <li><button type="submit" class="btn-default" data-icon="save">保存</button></li>
    </ul>
</div>